package com.example.button_basic;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn1 = findViewById(R.id.button1);
        btn1.setOnClickListener(new MyListener());
        Button btn2 = findViewById(R.id.button2);
        btn2.setOnClickListener(e->Log.e("Tag","匿名内部类实现"));
        Button btn3 = findViewById(R.id.button3);
        btn3.setOnClickListener(new MainActivity());
    }

    public void myOnclick(View v){
        switch (v.getId()){
            case R.id.button4:
                Log.e("TAG","Button4 进行点击");
                break;
            case R.id.button5:
                Log.e("TAG","Button5 进行点击");
                break;
        }
    }

    @Override
    public void onClick(View v) {
        Log.e("TAG","本类方式进行处理");
    }
}
class MyListener implements View.OnClickListener{

    @Override
    public void onClick(View v) {
        Log.e("TAG","内部类方式进行处理");
    }
}